/**
 *  This is a class to store the game info
 */
import java.util.Hashtable;
import java.util.Map;
import java.util.Random;

/**
 * @author Master
 * @version $Revision: 1.0 $
 */
public class GameInfo {
	/**
	 * Field SANWANLIU.
	 * (value is 36000)
	 */
	private static final int SANWANLIU = 36000;

	/**
	 * Field WU.
	 * (value is 5)
	 */
	private static final int WU = 5;

	/**
	 * Field SI.
	 * (value is 4)
	 */
	private static final int SI = 4;

	/**
	 * Field SAN.
	 * (value is 3)
	 */
	private static final int SAN = 3;

	/**
	 * Field ER.
	 * (value is 2)
	 */
	private static final int ER = 2;

	/**
	 * Field SHENMEDONGXI.
	 * (value is 931022)
	 */
	private static final int SHENMEDONGXI = 931022;

	/**
	 * Field engineerSP.
	 */
	/**
	 * Field traderSP.
	 */
	/**
	 * Field fighterSP.
	 */
	/**
	 * Field pilotSP.
	 */
	/**
	 * Field difficulty.
	 */
	public static int Difficulty=0, PilotSP=0, FighterSP=0, TraderSP=0, EngineerSP=0;

	/**
	 * Field name.
	 */
	public static String Name="";

	/**
	 * Field universe.
	 */
	public static Universe Universe=null;

	/**
	 * Field random.
	 */
	public static Random Rand=null;

	/**
	 * Field Location.
	 */
	public static Map<Integer,Integer> Location=null;

	/**
	 * Field currentPlanetListener.
	 */
	public static PlanetListener CurrentPlanetListener=null;
	
	/**
	 * Field instance.
	 */
	private static volatile GameInfo Instance = null;
	
	/**
	 * Constructor for GameInfo.
	 * @param name String
	 * @param difficulty int
	 * @param pilotSP int
	 * @param fighterSP int
	 * @param traderSP int
	 * @param engineerSP int
	 */
	public GameInfo(String name, int difficulty,
			int pilotSP, int fighterSP, int traderSP, int engineerSP){
		Rand=new Random(SHENMEDONGXI);
		Location=new Hashtable<Integer, Integer>();
		GameInfo.Name = name;
		GameInfo.Difficulty = difficulty;
		GameInfo.PilotSP = pilotSP;
		GameInfo.FighterSP = fighterSP;
		GameInfo.TraderSP = traderSP;
		GameInfo.EngineerSP = engineerSP;
		GameInfo.Universe=new Universe();
		new PlayerInfo();
	}

	/**
	 * Method getInstance.
	
	 * @return GameInfo */
	public static GameInfo getInstance() {
        if (Instance == null) {
                synchronized (GameInfo.class){
                        if (Instance == null) {
                                Instance = new GameInfo();
                        }
              }
        }
        return Instance;
	}
	
	/**
	 * Constructor for GameInfo.
	 */
	public GameInfo(){
		this("", 0, 0, 0, 0, 0);
	}

	/**
	 * Method getName.
	
	 * @return String */
	public static String getName() {
		return GameInfo.Name;
	}

	/**
	 * Method setName.
	 * @param name String
	 */
	public static void setName(String name) {
		GameInfo.Name = name;
	}

	/**
	 * Method getDifficulty.
	
	 * @return String */
	public static String getDifficulty() {
		if (GameInfo.Difficulty == 0) {
			return "Beginner";
		}else if (GameInfo.Difficulty == 1) {
			return "Easy";
		}else if (GameInfo.Difficulty == ER) {
			return "Normal";
		}else if (GameInfo.Difficulty == SAN) {
			return "Hard";
		}else return "Impossible";
	}

	/**
	 * Method setDifficulty.
	 * @param d String
	 */
	public static void setDifficulty(String d) {
		if (d.equals("Beginner")) {
			GameInfo.Difficulty=0;
		}else if (d.equals("Easy")) {
			GameInfo.Difficulty=1; 
		}else if (d.equals("Hard")) {
			GameInfo.Difficulty=SAN;
		}else if (d.equals("Impossible")) {
			GameInfo.Difficulty=SI;
		}
		PlayerInfo.setMoney(PlayerInfo.getMoney() * (WU - Difficulty) / WU);
		if (d.equals("Normal")) {
			GameInfo.Difficulty=ER;
			PlayerInfo.setMoney(SANWANLIU);
		}
	}

	/**
	 * Method getPilotSP.
	
	 * @return int */
	public static int getPilotSP() {
		return PilotSP;
	}

	/**
	 * Method setPilotSP.
	 * @param pilotSP int
	 */
	public static void setPilotSP(int pilotSP) {
		GameInfo.PilotSP = pilotSP;
	}

	/**
	 * Method getFighterSP.
	
	 * @return int */
	public static int getFighterSP() {
		return FighterSP;
	}

	/**
	 * Method setFighterSP.
	 * @param fighterSP int
	 */
	public static void setFighterSP(int fighterSP) {
		GameInfo.FighterSP = fighterSP;
	}

	/**
	 * Method getTraderSP.
	
	 * @return int */
	public static int getTraderSP() {
		return TraderSP;
	}

	/**
	 * Method setTraderSP.
	 * @param traderSP int
	 */
	public static void setTraderSP(int traderSP) {
		GameInfo.TraderSP = traderSP;
	}

	/**
	 * Method getEngineerSP.
	
	 * @return int */
	public static int getEngineerSP() {
		return EngineerSP;
	}

	/**
	 * Method setEngineerSP.
	 * @param engineerSP int
	 */
	public static void setEngineerSP(int engineerSP) {
		GameInfo.EngineerSP = engineerSP;
	}

	/**
	 * Method getUniverse.
	
	 * @return Universe */
	public static Universe getUniverse() {
		return Universe;
	}

	/**
	 * Method setUniverse.
	 * @param universe Universe
	 */
	public static void setUniverse(Universe universe) {
		GameInfo.Universe = universe;
	}

	/**
	 * Method getRandom.
	
	 * @return Random */
	public static Random getRandom() {
		return Rand;
	}

	/**
	 * Method setRandom.
	 * @param random Random
	 */
	public static void setRandom(Random random) {
		GameInfo.Rand = random;
	}

	/**
	 * Method getLocation.
	
	 * @return Hashtable<Integer,Integer> */
	public static Map<Integer,Integer> getLocation() {
		return Location;
	}

	/**
	 * Method setLocation.
	 * @param location Hashtable<Integer,Integer>
	 */
	public static void setLocation(Map<Integer,Integer> location) {
		Location = location;
	}

	/**
	 * Method toString.
	
	 * @return String */
	public String toString(){
		String s="";
		s+="name: " + Name + " difficulty: " + getDifficulty() + " pilotSP: " + PilotSP;
		s+=" fighterSP: " + FighterSP + " traderSP: " +
		   TraderSP + " engineerSP:" + EngineerSP;
		return s;
	}
}
